import axios from '@/libs/api.request'


// 密码登录
export const login = ({ userName, password }) => {
  const data = {
    userName,
    password
  }
  return axios.request({
    url: '/api/v1/login/login_pass',
    data,
    method: 'post'
  })
}


// 验证码登录
export const dxLogin = ({ phone_number, otp }) => {
  const data = {
    phone_number,
    otp
  }
  return axios.request({
    url: '/api/v1/login/login_otp',
    data,
    method: 'post'
  })
}

// 获取验证码
export const getOtp = ({ phoneNumber }) => {
  const data = {
    phoneNumber,
  }
  return axios.request({
    url: '/api/v1/send_opt',
    data,
    method: 'post'
  })
}


// 解析文本
export const analysisText = ({ text }) => {
  const data = {
    text
  }
  return axios.request({
    url: '/api/v1/refine_message',
    data,
    method: 'post'
  })
}

// 注册
export const register = ({ userName, phoneNumber,password,otp }) => {
  const data = {
    username:userName,
    phone_number:phoneNumber,
    password:password,
    otp:otp
  }
  return axios.request({
    url: '/api/v1/register',
    data,
    method: 'post'
  })
}

export const getUserInfo = (token) => {
  return axios.request({
    url: 'get_info',
    params: {
      token
    },
    method: 'get'
  })
}

export const logout = (token) => {
  return axios.request({
    url: 'logout',
    method: 'post'
  })
}

export const getUnreadCount = () => {
  return axios.request({
    url: 'message/count',
    method: 'get'
  })
}

export const getMessage = () => {
  return axios.request({
    url: 'message/init',
    method: 'get'
  })
}

export const getContentByMsgId = msg_id => {
  return axios.request({
    url: 'message/content',
    method: 'get',
    params: {
      msg_id
    }
  })
}

export const hasRead = msg_id => {
  return axios.request({
    url: 'message/has_read',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const removeReaded = msg_id => {
  return axios.request({
    url: 'message/remove_readed',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const restoreTrash = msg_id => {
  return axios.request({
    url: 'message/restore',
    method: 'post',
    data: {
      msg_id
    }
  })
}
